#pragma once

#include <stdint.h>
#include <time.h>

class StopWatch {
public:
	void Start() {
		clock_gettime(CLOCK_MONOTONIC, &tick_);
	}

	int64_t CostMs() {
		struct timespec tock;
		clock_gettime(CLOCK_MONOTONIC, &tock);

		int64_t sec = tock.tv_sec - tick_.tv_sec;
		int64_t nsec = tock.tv_nsec - tick_.tv_nsec;

		return sec * 1000 + nsec / (1000 * 1000);
	}

private:
	struct timespec tick_;
};
